#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
void* dowork(void* arg)
{
        printf("I am thread,pid=%d, tid = %lu\n",getpid(),pthread_self());
        return NULL;
}
int main(int argc, char const *argv[])
{
        int cpuNum;
        int i;
        cpuNum = sysconf(_SC_NPROCESSORS_ONLN);
        pthread_t tid[cpuNum-1];
        pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
        for (i = 0; i < cpuNum-1; i++){
                pthread_create(&tid[i], &attr,dowork,NULL);
        }
        pthread_attr_destroy(&attr);
        printf("main thread pid=%d,tid=%lu\n", getpid(),pthread_self());
        pthread_exit(NULL);
        return 0;
}
